#include <stdio.h>
#include <stdlib.h>

int main (int argc, char const* argv[])
{
    int id, cnt, mark, marks[10240], ans, i, t;

    while (scanf("%d", &id) != EOF) {
        cnt = 0;
        while (++cnt) {
            scanf("%d %d", &t, &marks[cnt]);
            if (t == 0 && marks[cnt] == 0) break;
            if (t == id) {
                mark = marks[cnt];
                cnt--;
            }
        }

        ans = 1;
        for (i = 0; i < cnt; i++) {
            if (marks[i] > mark) {
                ans++;
            }
        }

        printf("%d\n", ans);
    }

    return 0;
}
